package com.adinnet.admin.order.controller;


import com.adinnet.admin.common.service.CommonService;
import com.adinnet.admin.order.model.vo.OrderReq;
import com.adinnet.admin.order.model.vo.OrderResp;
import com.adinnet.admin.order.service.OrderService;
import com.adinnet.admin.organization.service.OrganizationService;
import com.adinnet.admin.school.service.SchoolService;
import com.adinnet.admin.system.model.vo.SysUserInfo;
import com.adinnet.core.BaseController;
import com.adinnet.core.JsonResult;
import com.adinnet.core.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-16
 */
@Controller
@RequestMapping("admin/order")
public class OrderController extends BaseController {


    @Autowired
    private OrganizationService organizationService;

    @Autowired
    private SchoolService schoolService;

    @Autowired
    private CommonService commonService;

    @Autowired
    private OrderService orderService;


    @RequestMapping()
    public String order(Model model) {
        SysUserInfo sysUserInfo = commonService.getLoginUser();
        model.addAttribute("organizationList", organizationService.getListByUserRole(sysUserInfo));//机构列表
        model.addAttribute("schoolList", schoolService.getListByUserRole(sysUserInfo));//校区列表
        return "order/order.html";
    }


    /**
     * 根据权限查询订单列表
     **/
    @ResponseBody
    @RequestMapping("/list")
    public PageResult<OrderResp> list(OrderReq orderReq) {
        SysUserInfo sysUserInfo = commonService.getLoginUser();
        return orderService.orderList(orderReq, sysUserInfo);
    }

    /**
     * 修改订单状态
     **/
    @ResponseBody
    @RequestMapping("/updateStatus")
    public JsonResult updateStatus(Integer orderId, HttpServletRequest request) {
        commonService.saveOperation(request,"完成收货，订单ID："+orderId);
        return orderService.updateStatus(orderId);
    }

}
